package utils

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// Response JSON 返回结构体
type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

// SuccessJSON 成功返回 JSON
func SuccessJSON(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, &Response{
		Code:    200,
		Message: "success",
		Data:    data,
	})
}

// ErrorJSON 失败返回 JSON
func ErrorJSON(c *gin.Context, code int, message string) {
	c.JSON(http.StatusOK, &Response{
		Code:    code,
		Message: message,
	})
}
